#!/bin/bash

wc_read_version() {
    version=$1
    if [ -z "${version}" ]; then
        version=$(git describe --long --tags | cut -f 1 -d "-")
    fi
    echo ${version}
}

wc_release_url() {
    tag="$1"

    id=$(curl -u ${GITHUB_USER}:${GITHUB_TOKEN} "https://api.github.com/repos/trustwallet/wallet-core/releases/tags/${tag}" | jq ".id")
    if [[ $id == "null" ]]; then
        echo "Failed to get release id for tag ${tag}"
        exit 22
    fi
    release_url="https://uploads.github.com/repos/trustwallet/wallet-core/releases/${id}"
    echo ${release_url}
}

wc_upload_asset() {
    tag="$1"
    filename="$2"

    gh release upload $tag $filename --clobber
    download_url=$(gh release view $tag --json assets --jq '.assets.[] | select(.name == "'"${filename}"'") | .url')
    echo "\"${download_url}\""
}
